﻿using T4UtilityBelt.DataDesigns;
using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Controls.Renderers.Windows
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes")]
    public abstract class PropertyRenderer<TControl, TRenderer, TProperty> : ControlRenderer<TControl, TRenderer>, IPropertyRenderer<TControl, TRenderer, TProperty> 
        where TControl : PropertyControl<TControl, TRenderer, TProperty>
        where TRenderer : class, IPropertyRenderer<TControl, TRenderer, TProperty>
        where TProperty : Property
    {
        protected override void OnRenderUiXmlBegin(TControl control, CodeWriter writer)
        {
            //if (control.HasLabel != HasLabel.None)
            //{
            //    control.StackPanel.RenderUiXmlBegin(writer);
            //}
            //if (control.HasLabel == HasLabel.Top
            //    || control.HasLabel == HasLabel.Left)
            //{
            //    control.Label.RenderUiXml(writer);
            //}
            if (control.ReadOnly)
            {
                OnRenderUiXmlContentReadOnly(control, writer);
            }
            else
            {
                OnRenderUiXmlContentInput(control, writer);
            }
        }

        protected abstract void OnRenderUiXmlContentReadOnly(TControl control, CodeWriter writer);

        protected abstract void OnRenderUiXmlContentInput(TControl control, CodeWriter writer);

        protected override void OnRenderUiXmlEnd(TControl control, CodeWriter writer)
        {
            //if (control.HasLabel == HasLabel.Bottom
            //    || control.HasLabel == HasLabel.Right)
            //{
            //    control.Label.RenderUiXml(writer);
            //}
            //if (control.HasLabel != HasLabel.None)
            //{
            //    control.StackPanel.RenderUiXmlEnd(writer);
            //}
        }
    }
}